﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
using System.Windows.Media;

namespace BallData
{
    class ShowMathItemForCaiPiao : IListenMatchItem
    {
        private MainUIControl uicontrol;

        public MainUIControl Uicontrol
        {
            get { return uicontrol; }
            set { uicontrol = value; }
        }
        public void ListenEnd()
        {
            TabItem tb = Uicontrol.getTabItemByName(OddsUntil.WinLoseCaiPiaoName);
            ListView listview = null;
            if (tb == null)
            {
                tb = new TabItem();
                listview = Uicontrol.NewListView();

                tb.Content = listview;
                tb.Header = OddsUntil.WinLoseCaiPiaoName;

                tb.DataContext = OddsUntil.WinLoseCaiPiaoName;
            }
            listview = tb.Content as ListView;

            ObservableCollection<MatchListDataTemple> matchlist = new ObservableCollection<MatchListDataTemple>();
            foreach (MatchItem matchitem in this.Uicontrol.getMatchData().Matchs.Values)
            {

                // 找到足彩竞猜比赛
                if (this.Uicontrol.getCaiPiaoMaths().Contains(matchitem.mId))
                {

                    LeagueItem leagueitem = this.Uicontrol.getMatchData().LeagueList[matchitem.lId] as LeagueItem;
                    
                    CompanyOdds sh = this.Uicontrol.getMatchData().companymatchsodds["1"] as CompanyOdds;
                    OddsInfo odds_asia = null, odds_eupro = null, odds_bigsmall = null;

                    if (sh != null)
                    {
                        Hashtable mList = sh.o_data.MatchList[matchitem.mId] as Hashtable;

                        OddsUntil.GetDataBymList(ref odds_asia, ref odds_eupro, ref odds_bigsmall, ref mList);

                    }
                    MatchListDataTemple matchlistdatatemple = new MatchListDataTemple
                    {
                        LeagueName = leagueitem.cnName,
                        LeagueColor = leagueitem.color,
                        MatchHost = matchitem.t1CnName,
                        MatchVisit = matchitem.t2CnName,
                        CompanyName = "澳门",
                        CompanyColor = OddsUntil.White,
                        Odds_a_host = odds_asia.host,
                        Odds_a_vs = OddsUntil.GetVsName(odds_asia.vs, "tr"),
                        Odds_a_visit = odds_asia.visit,

                        Odds_e_host = odds_eupro.host,
                        Odds_e_vs = odds_eupro.vs,
                        Odds_e_visit = odds_eupro.visit,

                        Odds_o_host = odds_bigsmall.host,
                        Odds_o_vs = OddsUntil.GetTotalName(odds_bigsmall.vs),
                        Odds_o_visit = odds_bigsmall.visit,
                        mId = matchitem.mId,
                        MatchKoTime = matchitem.koDay,

                        Odds_a_host_color = OddsUntil.White,
                        Odds_a_visit_color = OddsUntil.White,

                        Odds_o_host_color = OddsUntil.White,
                        Odds_o_visit_color = OddsUntil.White,

                        Odds_e_host_color = OddsUntil.White,
                        Odds_e_visit_color = OddsUntil.White,

                        Odds_a_chgtime = odds_asia.chgTime,
                        Odds_e_chgtime = odds_eupro.chgTime,
                        Odds_o_chgtime = odds_bigsmall.chgTime,


                    };
                    // 保存比赛显示信息模版
                    OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(matchitem.mId, sh.cId)] = matchlistdatatemple;

                    if (!OddsUntil.IsInMatchListDataTemple(matchlist, matchlistdatatemple))
                        matchlist.Add(matchlistdatatemple);

                }

            }
            // 保存联盟赛事的显示信息模版
            if (tb.DataContext != null)
            {
                OddsUntil.LeagueViewTemple[tb.DataContext as String] = matchlist;
                listview.ItemsSource = matchlist;


                if (!this.Uicontrol.getLeagueTab().Items.Contains(tb))
                {
                    this.Uicontrol.getLeagueTab().Items.Add(tb);
                }

            }
            else
            {
                Console.WriteLine("找不到联盟对应ID");
            }
        
        }
        public void OnListenMathItem(MatchItem ci, MainUIControl ui)
        {

            
        }

    }
}
